/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @Task.java  2014年9月22日 下午8:36:33 - Guzhu
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.entity;

import com.android.support.httpclient.HttpCallBack;
import com.android.support.httpclient.HttpClientAsync;
import com.android.support.httpclient.HttpParams;
import com.android.tiango.baba.cookie.HttpUrl;
import com.android.tiango.baba.cookie.ShareCookie;
import com.android.tiango.baba.util.ToastUtils;
import com.nineoldandroids.util.StringUtil;

public enum Task {
	// // /每日签到
	taskOthersShare("外部分享", "RW009"), taskTianGouShare("内部分享", "RW003"), taskSign("每日签到", "RW001"), taskPltiezi(
			"评论贴子", "RW006"), taskShowOrderNotImage("晒单不贴图", "RW007"), taskShowOrderImage("晒单贴图",
			"RW0010"), taskInjoy("加入吧", "RW005"), taskPeopleData("个人资料	", "RW008"), taskQiangGou(
			"参与商品抢购", "RW004"), taskFaTie("发帖", "RW002"), taskQianggouCG("抢购成功额外经验值", "RW011");

	// // /关注腾讯微博
	String name;
	String TaskId;

	private Task(String name, String TaskId) {
		this.name = name;
		this.TaskId = TaskId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTaskId() {
		return TaskId;
	}

	public void setTaskId(String taskId) {
		TaskId = taskId;
	}

	public String getTaskId(String name) {
		for (Task t : Task.values()) {
			if (t.getName().equals(name)) {
				return t.TaskId;
			}
		}
		return "";
	}

	public String getTaskName(String TaskId) {
		for (Task t : Task.values()) {
			if (t.getTaskId().equals(TaskId)) {
				return t.name;
			}
		}
		return "";
	}

	public static void finishTask(Task ruleCode) {
		finishTask(ruleCode.getTaskId());
	}
	
	public static void finishTask(String ruleCode) {
		HttpClientAsync httpClientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("token", ShareCookie.getToken());
		params.put("ruleCode", ruleCode);
		httpClientAsync.post(HttpUrl.getUrl(HttpUrl.FinishTask), params, new HttpCallBack() {

			@Override
			public void onHttpSuccess(Object arg0) {
				ToastUtils.showMessage("任务完成");
			}

			@Override
			public void onHttpStarted() {

			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				if (StringUtil.isEmpty(arg1)) {
					arg1 = "网络错误";
				}
				ToastUtils.showMessage(arg1);
			}
		}, BaseEntity.class);
	}

}
